package ar.cpfw.hibernate.mapping.valueobjects;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity(name = "Person")
@Table(name = "persons")
public class Person {
	@Id
	@Column(name = "person_id")
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	private String id;

	@ElementCollection(fetch = FetchType.EAGER)
	@CollectionTable(name = "colours", joinColumns = @JoinColumn(name = "person_id"))
	@Column(name = "colours")
	private Set<String> colours = new HashSet<String>();

	@ElementCollection
	@CollectionTable(name = "phones", joinColumns = @JoinColumn(name = "person_id"))
	private Set<Phone> phones = new HashSet<Phone>();

	@Embedded
	private Address address;
	
	public Person() {

	}

	public void addPhone(Phone malcolm) {
		phones.add(malcolm);
	}

	public Set<Phone> getPhones() {
		return phones;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public void setPhones(Set<Phone> phones) {
		this.phones = phones;
	}

	public Set<String> getColours() {
		return colours;
	}

	public void setColours(Set<String> colours) {
		this.colours = colours;
	}

	public void addColour(String colour) {
		colours.add(colour);
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}
